package utils

import (
	"fmt"
	"gopkg.in/yaml.v3"
	"os"
)

var (
	AppMode  string
	HttpPort string
	JwtKey   string

	DbName     string
	DbUser     string
	DbPassword string
	DbHost     string
	DbPort     string
	Db         string
)

type Server struct {
	AppMode  string `yaml:"AppMode"`
	HttpPort string `yaml:"HttpPort"`
	JwtKey   string `yaml:"JwtKey"`
}
type Database struct {
	DbName     string `yaml:"DbName"`
	DbUser     string `yaml:"DbUser"`
	DbPassword string `yaml:"DbPassword"`
	DbHost     string `yaml:"DbHost"`
	DbPort     string `yaml:"DbPort"`
	Db         string `yaml:"Db"`
}
type Config struct {
	Server   Server   `yaml:"server"`
	Database Database `yaml:"database"`
}

func init() {
	file, err := os.ReadFile("config/config.yaml")
	if err != nil {
		fmt.Println("文件读取失败", err)
		return
	}
	var config Config
	err = yaml.Unmarshal(file, &config)
	if err != nil {
		fmt.Println("yaml解析失败", err)
		return
	}
	AppMode = config.Server.AppMode
	HttpPort = config.Server.HttpPort
	JwtKey = config.Server.JwtKey
	DbName = config.Database.DbName
	DbUser = config.Database.DbUser
	DbPassword = config.Database.DbPassword
	DbHost = config.Database.DbHost
	DbPort = config.Database.DbPort
	Db = config.Database.Db

}
